package edu.gatech.cs2340.group7.wheresmystuffapp.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.presenters.MatchedItemPresenter;

public class MatchedItemView extends Activity implements OnClickListener {
	private String PACKAGE_NAME;
	private MatchedItemPresenter myPresenter;
	private TextView MatchedItemList;
	private Button backButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_matched_items);
		initialize();
		PACKAGE_NAME = getPackageName();
		myPresenter.matchItems();
	}

	/**
	 * Initializes the views in the XML layout file, and sets the listener for the button
	 */
	private void initialize() {
		myPresenter = new MatchedItemPresenter(this);
		MatchedItemList = (TextView) findViewById(R.id.MatchedItemsList);

		backButton = (Button) findViewById(R.id.b_Matched_Items_Back);
		backButton.setOnClickListener(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_display_main_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(this, UserMainMenuView.class);
		intent.setPackage(PACKAGE_NAME);
		startActivity(intent);

	}

	/**
	 * Displays the list of matched items that the user has
	 * @param result the list of items to display
	 */
	public void displayMatchedItems(String result) {
		MatchedItemList.setText(result);
	}

}
